package com.selfdriving.adapter;

import java.util.List;
import com.selfdriving.R;
import com.selfdriving.activity.BaseMapDemo;
import com.selfdriving.bean.Feature;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SearchAdapter extends BaseAdapter {
	private Context context;

	private List<Feature> features;
	
	private HolderView holderView;

	public SearchAdapter(Context context,List<Feature> features) {
		this.context = context;
		this.features = features;
	}

	@Override
	public int getCount() {
		return features.size();
	}

	@Override
	public Object getItem(int position) {
		return features.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int arg0, View view, ViewGroup arg2) {
		if (view == null) {
			holderView = new HolderView();
			view = ((LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
					.inflate(R.layout.feature_guide_item, null);
			view.setTag(holderView);
		} else {
			holderView = (HolderView) view.getTag();
		}
		holderView.guide = (Button) view.findViewById(R.id.btnGuide);
		holderView.guide.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context,BaseMapDemo.class);
				context.startActivity(intent);
			}
		});
		return view;
	}
	
	private class HolderView{
		private ImageView icon;
		
		private TextView distance;
		
		private ImageView sex;
		
		private Button guide;
	}

}
